package org.hoyi.disptachs.model;

import java.io.Serializable;

import net.sf.json.JSONObject;


/**
 *          Author:ellen
 *          Email:ellen@kuaifish.com
 *          CreateDate:2015-05-20
 *          ModifyDate:2015-06-20
 *          hoyi entities @ hoyi.org
 *          使用请在项目关于内标注hoyi版权，
 *          hoyi版权归hoyi.org所有
 */
public class JsonModel implements Serializable {
	private static final long serialVersionUID = 954245970633237373L;
	private String status = "-999";
	private String msg;
	private Object data;

	public JsonModel() {
	}

	public JsonModel(Object data) {
		this.data = data;
	}

	public JsonModel(String _msg) {
		this.msg = _msg;
	}

	public JsonModel(int _status, String _msg) {
		setStatus(_status);
		this.msg = _msg;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public JsonModel(int _status, String _msg, Object _data) {
		setStatus(_status);
		this.msg = _msg;
		this.data = _data;
	}

	public void setStatus(int _status) {
		this.status = String.valueOf(_status);
	}

	public int getStatus() {
		return Integer.parseInt(this.status);
	}

	public String getMsg() {
		return this.msg;
	}

	public JsonModel setMsg(String _msg) {
		this.msg = _msg;
		return this;
	}

	public Object getData() {
		return this.data;
	}

	public JsonModel setData(Object data) {
		this.data = data;
		return this;
	}
	
	public static JsonModel FromJson(String ret) {
		JsonModel retmodel = new JsonModel();
		JSONObject retobj = JSONObject.fromObject(ret);
		retmodel.setData(retobj.get("data"));
		retmodel.setMsg(retobj.getString("msg"));
		retmodel.setStatus(retobj.getInt("status"));
		return retmodel;
	}
}
